Skip to content

Refactor Report.js to remove Ion.get()#403

Merged
cead22 merged 35 commits into
masterfrom
tgolen-remove-get-report
Sep 8, 2020
Merged

Refactor Report.js to remove Ion.get()#403
cead22 merged 35 commits into
masterfrom
tgolen-remove-get-report

Conversation

@tgolen

@tgolen tgolen commented Sep 4, 2020

Copy link
Copy Markdown
Contributor

I know this is a huge PR that touches a lot of things, but most of them are pretty superficial. This PR contains:

  1. Replaces all references to "report history" with "report actions" (this is the bulk of superficial changes)
  2. Removes all Ion.get() references in Report.js
  3. Greatly simplifies all promise chains in Report.js to reflect the beauty of Ion being fully asynchronous (no need to do so many things as a sequence of promises)

Tests

Need to do general regression testing on pretty much everything. Be sure to test the following flow:

  1. User A is in the chat app
  2. Create a new user B on the same policy as user A
  3. In a separate browser, sign into the chat app with User B
  4. Have user B use the chat switcher to start a conversation with User A
  5. Verify that the chat shows up for User A
  6. Verify that notifications work
  7. Verify that the unread indicator works

cc @quinthar

@tgolen tgolen requested review from Jag96 and cead22 September 4, 2020 04:11
@tgolen tgolen self-assigned this Sep 4, 2020
Comment thread src/IONKEYS.js Outdated
*/
export default {
ACTIVE_CLIENT_IDS: 'activeClientIDs',
ACTIVE_CLIENTS: 'active_clients',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The renaming of these keys is OK. If you want to have a "clean" local storage (with no unused keys), just sign out and sign back in

Comment thread src/page/home/MainView.js Outdated
return (
<>
{_.map(this.props.reports, report => (
{_.map(this.props.reports, report => report.reportID && (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When can reportID not be set? Might be worth a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good call. This might have only been something that happened in the middle of my refactoring so I will see if this can be removed.


componentDidUpdate(prevProps) {
// When the number of actions change, wait three seconds, then record the max action
// This will make the unread indicator go away if you receive comments in the same chat you're looking at

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so I understand, if I'm in a chat and a new message comes in, the channel name will be bold, and 3 seconds later it'll the channel name will no longer be bold?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, correct. Do you think that is good? The alternatives are:

  1. It always stays bold
  2. It doesn't turn bold at all
  3. The delay is changed
  4. Some other action makes it not bold anymore

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to add a little bit of logic to this so that it will only run this if you're currently looking at the report (or else if a comment comes in on a report you aren't looking at, it disappears from the sidebar after 3 seconds 😂 )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this, but I think this is ok for now. I say we don't need this because I'm guessing we're going to implement a marker like slack's (screenshot below) that denotes were the first unread message is (imo, not having this is a blocker for moving group convos to expensify, because it's very hard to know where you left off) and that will make this "sidebard unread indicator" unnecessary
image

/**
* This function is triggered from the ref callback for the scrollview. That way it can be scrolled once all the
* items have been rendered. If the number of items in our history have changed since it was last rendered, then
* items have been rendered. If the number of actions have changed since it was last rendered, then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has changed

import ChatSwitcherList from './ChatSwitcherList';
import ChatSwitcherSearchForm from './ChatSwitcherSearchForm';
import {fetchChatReport} from '../../../lib/actions/Report';
import {fetchOrCreateChatReport} from '../../../lib/actions/Report';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getChatReport is better imo

Comment thread src/page/home/sidebar/SidebarLink.js Outdated
};

const SidebarLink = (props) => {
if (!props.reportName) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will a report not have a name? might be worth a comment

Comment thread src/lib/actions/Report.js Outdated
* Get the chat report ID, and then the history, for a chat report for a specific
* Get the actions of a report
*
* @param {string} reportID

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be Number?

Comment thread src/lib/actions/Report.js Outdated
let reportID;

// Get the current users accountID and set it aside in a local variable
// which is used for checking if there are unread comments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outdated

Comment thread src/lib/actions/Report.js Outdated
* set of participants
*
* @param {string[]} participants
* @returns {Promise}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB * @returns {Promise} resolves with reportID

Comment thread src/lib/actions/Report.js Outdated
* @param {object} report
*/
function handleReportChanged(report) {
// Nothing can be done without a report ID and it's OK to fail gracefully

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add why/when this would happen

Comment thread src/lib/actions/Report.js Outdated
return;
}

if (report && report.reportName === undefined) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The first condition will always be true, or the if above will fail
  • NAB, use _.isUndefined, or !report.reportName

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, the underscore source says:

/** @deprecated since v4.0.0 - use `value === undefined` instead. */

I also don't want to do a falsy check because an empty string should be OK (as far as not having any code throw errors anywhere).

Comment thread src/IONKEYS.js Outdated
REPORT_ACTION: 'reportAction',
REPORT_HISTORY: 'report_history',
FIRST_REPORT_ID: 'first_report_id',
REPORT_ACTIONS: 'report_actions',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we all it reportActions? Basically let's just copy the database as near as possible. No need to switch from camelcase to underscore-separated.

Comment thread src/IONKEYS.js Outdated
FIRST_REPORT_ID: 'first_report_id',
MY_PERSONAL_DETAILS: 'my_personal_details',
NETWORK: 'network',
PERSONAL_DETAILS: 'personal_details',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what the NVP is called in the database? If not, can we rename it? Indeed, for all of these, can we use camelcase to match the database and NVP nomenclature?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll rename them to be camel case

@Jag96 Jag96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple nabs, other than the points found by @cead22 this LGTM.

Comment thread src/lib/actions/Report.js Outdated
_.each(fetchedReports, (report) => {
// Store only the absolute bare minimum of data in Ion because space is limited
const newReport = getSimplifiedReportObject(report, accountID);
const newReport = getSimplifiedReportObject(report);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nab - unnecessary const

Comment thread src/lib/actions/Report.js Outdated
function fetchActions(reportID) {
return queueRequest('Report_GetHistory', {
reportID,
offset: 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nab - default offset is 0

@tgolen

tgolen commented Sep 4, 2020

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews, everyone! This has been updated to address everything.

@Jag96 Jag96 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/lib/actions/Report.js
callback: val => currentURL = val,
});

// Use a regex pattern here for an exact match so it doesn't also match "my_personal_details"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"my_personal_details" => "myPersonalDetails", although probably better to update this to just say // Use a regex pattern here for an exact match

Comment thread src/lib/actions/Report.js
if (newMaxSequenceNumber > previousMaxSequenceNumber) {
Ion.merge(`${IONKEYS.REPORT}_${reportID}`, {
hasUnread: true,
maxSequenceNumber: newMaxSequenceNumber,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same value that was set in the call to Ion.merge above, so maybe we can condense these two calls into one

    Ion.merge(`${IONKEYS.REPORT}_${reportID}`, {
        reportID,
        maxSequenceNumber: reportAction.sequenceNumber,
        hasUnread: reportAction.sequenceNumber > reportMaxSequenceNumbers[reportID]
    });

Comment thread src/lib/actions/Report.js
*/
function addHistoryItem(reportID, reportComment) {
const historyKey = `${IONKEYS.REPORT_HISTORY}_${reportID}`;
function addAction(reportID, text) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reportComment is a way better name than text. Not sure if you changed this to match the database, but text doesn't really match anything, and reportComment is a common term we use (plus the action for these is ADDCOMMENT to there is a similarity in the names)

@tgolen tgolen requested a review from AndrewGable as a code owner September 8, 2020 21:57
@cead22 cead22 merged commit be446dc into master Sep 8, 2020
@cead22 cead22 deleted the tgolen-remove-get-report branch September 8, 2020 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants